package thread.hc;

/**
 * @author ykh
 */
public class AccountSync implements Account {
    private Integer balance;

    public void AccountUnsafe(Integer balance) {
        this.balance = balance;
    }

    @Override
    public Integer getBalance() {
        synchronized (this) {
            return this.balance;
        }
    }
    @Override
    public void withdraw(Integer amount) {
        synchronized (this) {
            this.balance -= amount;
        }
    }

    public static void main(String[] args) {
        final AccountSync accountSync = new AccountSync();
        accountSync.AccountUnsafe(10000);
        Account.demo(accountSync);
    }
}
